<?php
/**
 * UserController class file
 *
 * @author Chamara Bandara
 * @copyright Copyright &copy; 2011 Allion Technologies (Pvt) Ltd
 */
Yii::import('application.extensions.simple_image');

class UserController extends Controller {
   public $layout = '//layouts/column2';

   public function filters() {
      return array(
          'accessControl', // perform access control for CRUD operations
              // 'rights',
      );
   }

   public function allowedActions() {
      return 'AjaxChangePassword,UpdatePassword';
   }

   public function accessRules() {
      return array(
          array('allow', // allow all users to perform 'index' and 'view' actions
              'actions' => array('AjaxChangePassword', 'UpdatePassword'),
              'users' => array('*'),
          ),
          array('allow', // allow authenticated user to perform 'create' and 'update' actions
              //'actions'=>array('create','update','admin','Approve','disApprove'),
              'users' => array('@'),
          ),
          array('allow', // allow admin user to perform 'admin' and 'delete' actions
              //'actions'=>array('chamara','delete'),
              'users' => array('chamara'),
          ),
          array('deny', // deny all users
              'users' => array('*'),
          ),
      );
   }

   public function actions() {
      return array(
          'index' => 'application.controllers.User.IndexAction',
          'create' => 'application.controllers.User.CreateAction',
          'view' => 'application.controllers.User.ViewAction',
          'update' => 'application.controllers.User.UpdateAction',
          'delete' => 'application.controllers.User.DeleteAction',
          'admin' => 'application.controllers.User.AdminAction',
          'approve' => 'application.controllers.User.ApproveAction',
          'disApprove' => 'application.controllers.User.DisApproveAction',
          'ajaxChangePassword' => 'application.controllers.User.AjaxChangePasswordAction',
          'ajaxUpdatePassword' => 'application.controllers.User.AjaxUpdatePasswordAction',
          'updatePassword' => 'application.controllers.User.UpdatePasswordAction',
      );
   }

   protected function performAjaxValidation($model) {
      if (isset($_POST['ajax']) && $_POST['ajax'] === 'user-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
      }
   }
}